<template>
  <div class="product-detail">
    <div class="page-header">
      <div class="container">
        <h1>{{ product.name }}</h1>
        <p>{{ product.subtitle }}</p>
      </div>
    </div>

    <div class="container" style="margin-top: 60px; padding-bottom: 80px">
      <el-row :gutter="40">
        <el-col :span="16">
          <img v-if="product.cover_image" :src="product.cover_image" :alt="product.name" class="product-image" />
          <div class="product-content" v-html="product.content"></div>
        </el-col>
        <el-col :span="8">
          <div class="product-info card">
            <h3>产品信息</h3>
            <div class="info-item">
              <span>浏览量:</span>
              <span>{{ product.view_count }}</span>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { getProductDetail } from '@/api/portal'
import type { Product } from '@/types'

const route = useRoute()
const product = ref<Product>({} as Product)

const fetchDetail = async () => {
  try {
    const id = Number(route.params.id)
    const res = await getProductDetail(id)
    product.value = res.data
  } catch (error) {
    console.error('获取产品详情失败', error)
  }
}

onMounted(() => {
  fetchDetail()
})
</script>

<style scoped lang="scss">
.page-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  padding: 100px 0 60px;
  margin-top: 70px;
  text-align: center;

  h1 {
    font-size: 42px;
    margin-bottom: 16px;
  }

  p {
    font-size: 18px;
    opacity: 0.9;
  }
}

.product-image {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 24px;
}

.product-content {
  line-height: 1.8;
  font-size: 16px;
}

.product-info {
  position: sticky;
  top: 90px;

  h3 {
    margin-bottom: 20px;
  }
}

.info-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #f0f0f0;

  &:last-child {
    border-bottom: none;
  }
}
</style>

